//
//  ViewController.m
//  04-UI
//
//  Created by Snow on 16/7/19.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//  background
    UIImageView *imageOfbackgroud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"41_151008164557_5.jpg"]];
    [self.view addSubview:imageOfbackgroud];
    [imageOfbackgroud mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    UIView *view = [UIView new];
    [self.view addSubview:view];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.8;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    //SongName
    UILabel *labelOfSong = [UILabel new];
    [view addSubview:labelOfSong];
    [labelOfSong mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(self.view.mas_top).mas_equalTo(20);
        make.left.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    labelOfSong.text = @"12월24일-12月24日";
    labelOfSong.textAlignment = 1;
    labelOfSong.font = [UIFont systemFontOfSize:18];
    labelOfSong.textColor = [UIColor whiteColor];
    
    UIImageView *imageOfLeftButton = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Unknown"]];
    [view addSubview:imageOfLeftButton];
    [imageOfLeftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(20);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    //labelOfSinger
    UILabel *labelOfSinger = [UILabel new];
    [view addSubview:labelOfSinger];
    [labelOfSinger mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.left.mas_equalTo(150);
        make.top.mas_equalTo(50);
        make.height.mas_equalTo(30);
    }];
    labelOfSinger.text = @"아이유(IU)";
    labelOfSinger.textAlignment = 1;
    labelOfSinger.textColor = [UIColor whiteColor];
    
    UIView *viewOfLeft = [UIView new];
    UIView *viewOfRight = [UIView new];
    [view addSubview:viewOfLeft];
    [view addSubview:viewOfRight];
    [viewOfLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(labelOfSong.mas_bottom).mas_equalTo(15);
        make.right.mas_equalTo(labelOfSinger.mas_left).mas_equalTo(-10);
    }];
    [viewOfRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(labelOfSong.mas_bottom).mas_equalTo(15);
        make.left.mas_equalTo(labelOfSinger.mas_right).mas_equalTo(10);
    }];
    viewOfLeft.backgroundColor = [UIColor whiteColor];
    viewOfRight.backgroundColor = [UIColor whiteColor];
    
    //imageOfButton
    UIImageView *imageOfMV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_mv_icon"]];
    [view addSubview:imageOfMV];
    [imageOfMV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(labelOfSinger.mas_bottom).mas_equalTo(10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    UIImageView *imageOfSong = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"player_btn_sq_sel_normal"]];
    [view addSubview:imageOfSong];
    [imageOfSong mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(imageOfMV.mas_left).mas_equalTo(-10);
        make.top.mas_equalTo(labelOfSinger.mas_bottom).mas_equalTo(10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    UIImageView *imageOfDTS = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"player_btn_dts_on_pressed"]];
    [view addSubview:imageOfDTS];
    [imageOfDTS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageOfMV.mas_right).mas_equalTo(10);
        make.top.mas_equalTo(labelOfSinger.mas_bottom).mas_equalTo(10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
//  center picture
    UIImageView *imageOfCenter = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"41_151008164557_5.jpg"]];
    [self.view addSubview:imageOfCenter];
    [imageOfCenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(imageOfMV.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(300);
    }];
    imageOfCenter.layer.masksToBounds = YES;
    imageOfCenter.layer.cornerRadius = 150;
    
    //labelOfLiric
    UILabel *labelOfLiric = [UILabel new];
    [view addSubview:labelOfLiric];
    [labelOfLiric mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageOfCenter.mas_bottom).mas_equalTo(15);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.left.mas_equalTo(100);
        make.height.mas_equalTo(40);
    }];
    labelOfLiric.text = @"12월24일-IU";
    labelOfLiric.textColor = [UIColor colorWithRed:0.18 green:0.8 blue:0.58 alpha:1];
    labelOfLiric.textAlignment = 1;
    
    //UISlider
    UISlider *slider = [UISlider new];
    [view addSubview:slider];
    [slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(250);
        make.height.mas_equalTo(30);
        make.top.mas_equalTo(labelOfLiric.mas_bottom);
    }];
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    [slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    slider.minimumValue = 0;
    slider.maximumValue = 1;
    slider.value = 0.3;
    //time
    UILabel *labelOfLeftTime = [UILabel new];
    UILabel *labelOfRightTime = [UILabel new];
    [view addSubview:labelOfLeftTime];
    [view addSubview:labelOfRightTime];
    [labelOfLeftTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(slider.mas_left).mas_equalTo(5);
        make.top.mas_equalTo(labelOfLiric.mas_bottom).mas_equalTo(-5);
        make.height.mas_equalTo(40);
    }];
    [labelOfRightTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-5);
        make.left.mas_equalTo(slider.mas_right).mas_equalTo(5);
        make.top.mas_equalTo(labelOfLiric.mas_bottom).mas_equalTo(-5);
        make.height.mas_equalTo(40);
    }];
    labelOfLeftTime.text = @"00:53";
    labelOfRightTime.text = @"03:53";
    labelOfRightTime.textAlignment = 1;
    labelOfLeftTime.textAlignment = 1;
    labelOfLeftTime.textColor = [UIColor grayColor];
    labelOfRightTime.textColor = [UIColor grayColor];
    labelOfLeftTime.font = [UIFont systemFontOfSize:10];
    labelOfRightTime.font = [UIFont systemFontOfSize:10];
   
    //player
    UIButton *buttonOfPlay = [UIButton buttonWithType:UIButtonTypeSystem];
    [view addSubview:buttonOfPlay];
    [buttonOfPlay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(slider.mas_bottom).mas_equalTo(-10);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(90);
    }];
    [buttonOfPlay setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_play_highlight"] forState:UIControlStateNormal];
    [buttonOfPlay addTarget:self action:@selector(handlePlay:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *buttonOfLeft = [UIButton buttonWithType:UIButtonTypeSystem];
    [view addSubview:buttonOfLeft];
    [buttonOfLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(buttonOfPlay.mas_left).mas_equalTo(-10);
        make.centerY.mas_equalTo(buttonOfPlay.mas_centerY);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    
    [buttonOfLeft setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_pre_highlight"] forState:UIControlStateNormal];
    
    UIButton *buttonOfRight = [UIButton buttonWithType:UIButtonTypeSystem];
    [view addSubview:buttonOfRight];
    [buttonOfRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(buttonOfPlay.mas_right).mas_equalTo(10);
        make.centerY.mas_equalTo(buttonOfPlay.mas_centerY);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    [buttonOfRight setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_play_highlight"] forState:UIControlStateNormal];
    
    //flag
    NSArray *array = @[@"1", @"2", @"3", @"4", @"5"];
    for (NSInteger i = 0; i < 5; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:array[i]] forState:UIControlStateNormal];
        [view addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(buttonOfPlay.mas_bottom).mas_equalTo(10);
            make.bottom.mas_equalTo(self.view.mas_bottom).mas_equalTo(-10);
            make.left.mas_equalTo(self.view.mas_left).mas_equalTo((self.view.frame.size.width / 5) * i);
            make.width.mas_equalTo(self.view.frame.size.width / 5);
        }];
    }
}

- (void)handlePlay:(UIButton *)button
{
    [button removeTarget:self action:@selector(handlePlay:) forControlEvents:UIControlEventTouchUpInside];
    [button addTarget:self action:@selector(handlePause:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_pause_highlight"] forState:UIControlStateNormal];
}
- (void)handlePause:(UIButton *)button
{
    [button removeTarget:self action:@selector(handlePause:) forControlEvents:UIControlEventTouchUpInside];
    [button addTarget:self action:@selector(handlePlay:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:@"hp_player_btn_play_highlight"] forState:UIControlStateNormal];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
